﻿using System;
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;
namespace LightSwitchApplication
{
    public partial class SearchOrders
    {
        partial void Calculate_CanExecute(ref bool result)
        {
            // Write your code here.
            result = this.SellOrdersInPeriod.Any() || this.PurchaseOrdersInPeriod.Any();
        }

        partial void Calculate_Execute()
        {
            // Write your code here.
            this.Income = this.DataWorkspace.ApplicationData.SellOrdersInPeriod(this.StartDate, this.EndDate).
                Cast<SellOrder>().Sum(so => so.SubTotal);
            this.Expenditure = this.DataWorkspace.ApplicationData.PurchaseOrdersInPeriod(this.StartDate, this.EndDate).
                Cast<PurchaseOrder>().Sum(po => po.Total);
        }
    }
}
